package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AttributeTemplateAddNewDTO;
import cn.tedu.csmall.product.pojo.vo.AttributeTemplateListItemVO;
import cn.tedu.csmall.product.pojo.vo.AttributeTemplateStandardVO;
import cn.tedu.csmall.product.service.IAttributeTemplateService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 * 处理类别相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("/attribute-templates")
@Api(tags = "03. 属性模板模块")
public class AttributeTemplateController {



    @Autowired
    private IAttributeTemplateService attributeTemplateService;

    public AttributeTemplateController() {
        log.info("创建控制器对象：AttributeTemplateController");
    }

    // http://localhost:9080/attribute-templates/add-new
    @ApiOperation("添加属性模板")
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid AttributeTemplateAddNewDTO attributeTemplateAddNewDTO) {
        attributeTemplateService.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }



    // http://localhost:9080/album/delete
    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @PostMapping("/delete")
    public JsonResult delete(Long id) {
        log.debug("开始处理【根据id删除相册】的请求，参数：{}", id);
        attributeTemplateService.delete(id);
        return JsonResult.ok();
    }

    //http://localhost:9080/album/info?id=1
    @ApiOperation("根据id查询相册详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @GetMapping("/info")
    public JsonResult xx(Long id){
        log.debug("开始处理[根据id查询相册详情]的请求,参数: {}",id);
        AttributeTemplateStandardVO album = attributeTemplateService.getStandardById(id);
        return JsonResult.ok(album);
    }
    @ApiOperation("查询属性")
    @ApiOperationSupport(order = 420)
    @GetMapping("/list")
    public JsonResult list(){
        log.debug("开始处理[查询属性模板列表]的请求,参数,无");
        List<AttributeTemplateListItemVO> list = attributeTemplateService.list();
        return JsonResult.ok(list);
    }

}
